package com.company.modeldesign;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingDeque;

public class MyStack {


    private Queue<Integer> frontQueue=new LinkedBlockingDeque<>();
    /** Initialize your data structure here. */
    public MyStack() {

    }

    /** Push element x onto stack. */
    public void push(int x) {
        frontQueue.add(x);
    }

    /** Removes the element on top of the stack and returns that element. */
    public int pop() {
        int currentLengh = frontQueue.size();

        for (int i = 0; i < currentLengh-1; i++) {
            Integer poll = frontQueue.poll();
            frontQueue.add(poll);
        }
        Integer result = frontQueue.poll();
        return result;

    }

    /** Get the top element. */
    public int top() {
        int result = pop();
        frontQueue.add(result);
        return result;
    }

    /** Returns whether the stack is empty. */
    public boolean empty() {
        return frontQueue.isEmpty();
    }
}
